import fly from "./interceptors.js";
export default {
	  /**
	 * get方法，对应get请求
	 * @param {String} url [请求的url地址名称 对应interface中定义的key值]
	 * @param {Object} params [请求时携带的参数]
	 * @param {String} otherUrl [请求时额外url]
	 */
	  get: (url, params = {}, otherUrl = '') => {
	    return new Promise((resolve, reject) => {
	      fly.get(`${url}${otherUrl}`, { params: params })
	        .then(res => { resolve(res) })
	        .catch(err => { reject(err) })
	    })
	  },
	  /**
	   * post方法，对应post请求
	   * @param {String} url [请求的url地址名称 对应interface中定义的key值]
	   * @param {Object} params [请求时携带的参数]
	   * @param {String} otherUrl [请求时额外url]
	   * @param {Object} config [请求时额外传参]
	  */
	  post: (url, params, otherUrl = '', config = {}) => {
	    return new Promise((resolve, reject) => {
	      fly.post(`${url}${otherUrl}`, params, config)
	        .then(res => { resolve(res) })
	        .catch(err => { reject(err) })
	    })
	  },
	  /**
	   * put方法，对应put请求
	   * @param {String} url [请求的url地址名称 对应interface中定义的key值]
	   * @param {Object} params [请求时携带的参数]
	   * @param {String} otherUrl [请求时额外url]
	   * @param {Object} config [请求时额外传参]
	  */
	  put: (url, params, otherUrl = '', config = {}) => {
	    return new Promise((resolve, reject) => {
	      fly.put(`${url}${otherUrl}`, params, config)
	        .then(res => { resolve(res) })
	        .catch(err => { reject(err) })
	    })
	  },
	  /**
	   * delete方法，对应delete请求
	   * @param {String} url [请求的url地址名称 对应interface中定义的key值]
	   * @param {Object} params [请求时携带的url参数]
	   * @param {String} otherOption [请求额外参数 【otherUrl: 额外携带的url】【 data：body参数】]
	  */
	  delete: (url, params = {}, otherOption) => {
	    const oldOtherOption = {
	      otherUrl: '',
	      data: {}
	    }
	    let newOption = Object.assign(oldOtherOption, otherOption)
	    let urlPamamsStr = queryParams(params)
	    return new Promise((resolve, reject) => {
	      fly.delete(`${url}${newOption.otherUrl}${urlPamamsStr}`, { data: newOption.data })
	        .then(res => { resolve(res) })
	        .catch(err => { reject(err) })
	    })
	  },
	  /**
	   * axios请求方法。可以更强的自定义扩展，具体查看axios文档。目前只是为了项目统一请求简单包装了一下。
	   * @param {Object} config  axios请求里面参数
	   * @returns 
	   */
	  request: (config) => {
	    let oldConfig = {
	      method:'get'
	    }
	    let newConfig= Object.assign(oldConfig,config)
	    return new Promise((resolve, reject) => {
	      fly(newConfig).then(res => { resolve(res) })
	        .catch(err => { reject(err) })
	    })
	  }
}